from flask_appbuilder import Model
from sqlalchemy import Column, Integer, String, Text, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from myapp.models.helpers import AuditMixinNullable
from myapp.models.base import MyappModelBase

class Model_Version(Model, AuditMixinNullable, MyappModelBase):
    __tablename__ = 'model_version'
    
    id = Column(Integer, primary_key=True, comment='版本ID')
    model_id = Column(Integer, ForeignKey('model.id'), comment='模型ID')
    version_number = Column(String(50), comment='版本号')
    version_type = Column(String(20), comment='版本类型：major/minor/patch')
    changelog = Column(Text, comment='版本变更日志')
    is_active = Column(Boolean, default=True, comment='是否为活跃版本')
    performance_diff = Column(Text, default='{}', comment='与上一版本性能对比')
    
    model = relationship('Training_Model', backref='versions')